﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Linq;
using System.Web;

namespace Project_Udrinkwater
{
    public class UpdateDataEmp
    {
        string Connection = ConfigurationManager.ConnectionStrings["DB_Udrink"].ConnectionString;
        public void UpdatetimeEmp(Data DataTime,string T1)
        {
            string sqltext = @"UPDATE TB_Time_Cards SET Check_out=@Check_out 
                               WHERE Employee_ID=@Employee_ID AND (Check_in BETWEEN '" + T1 + " 00:00:00' AND '" + T1 + " 23:59:59')";
            SqlCommand sqlcomm = new SqlCommand();
            SqlConnection sqlconn = new SqlConnection(Connection);
            sqlcomm.Connection = sqlconn;
            sqlcomm.CommandType = System.Data.CommandType.Text;
            sqlcomm.CommandText = sqltext;
            sqlcomm.Parameters.AddWithValue("@Employee_ID", DataTime.Empoyee_ID);
            //sqlcomm.Parameters.AddWithValue("@Check_IN",DataTime.Checkin);
            sqlcomm.Parameters.AddWithValue("@Check_out",DataTime.Checkout);

            try
            {
                sqlcomm.Connection.Open();
                sqlcomm.ExecuteNonQuery();
            }
            catch (Exception)
            {

                sqlcomm.Connection.Close();
                sqlcomm.Connection.Dispose();
            }
            sqlcomm.Connection.Close();
            sqlcomm.Connection.Dispose();

        }
        public void UpdatetimeEmpOvertime(Data DataTime, string T1)
        {
            string sqltext = @"UPDATE TB_EmployeeOT SET [End_OT]=@End_OT,[Total_OT]=@TotalOT 
                               WHERE Employee_ID=@Employee_ID AND ([Start_OT] BETWEEN '" + T1 + " 00:00:00' AND '" + T1 + " 23:59:59')";
            SqlCommand sqlcomm = new SqlCommand();
            SqlConnection sqlconn = new SqlConnection(Connection);
            sqlcomm.Connection = sqlconn;
            sqlcomm.CommandType = System.Data.CommandType.Text;
            sqlcomm.CommandText = sqltext;
            sqlcomm.Parameters.AddWithValue("@Employee_ID", DataTime.Empoyee_ID);
            sqlcomm.Parameters.AddWithValue("@TotalOT", DataTime.Total_OT);
            sqlcomm.Parameters.AddWithValue("@End_OT", DataTime.End_OT);

            try
            {
                sqlcomm.Connection.Open();
                sqlcomm.ExecuteNonQuery();
            }
            catch (Exception)
            {

                sqlcomm.Connection.Close();
                sqlcomm.Connection.Dispose();
            }
            sqlcomm.Connection.Close();
            sqlcomm.Connection.Dispose();

        }
    }
}